﻿using System;
using System.Collections;
using System.Web;
using System.Web.Mvc;
using System.Net;

namespace TidyBlog.MVC.WWW.Controllers
{
    /// <summary>
    /// 后台首页控制器 /Manage_Home/{action}
    /// </summary>
    public class Manage_HomeController : ManageController
    {
        /// <summary>
        /// 后台首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            // 内存占用量
            ViewBag.MemTotal = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1024;
            // 服务器端应用程序服务器
            ViewBag.ServerSoft = Request.ServerVariables["SERVER_SOFTWARE"];
            // 服务器端操作系统
            ViewBag.ServerSys = Environment.OSVersion.VersionString;
            // 服务器端IP
            IPAddress[] addressList = Dns.GetHostAddresses(Dns.GetHostName());
            ViewBag.ServerAddress = addressList[0].ToString();
            // 服务器CPU核心个数
            ViewBag.ProcessorCount = Environment.ProcessorCount;

            return View();
        }

        /// <summary>
        /// 清空缓存
        /// </summary>
        /// <returns></returns>
        public ActionResult ClearCache()
        {
            var cache = this.ControllerContext.HttpContext.Cache;

            IDictionaryEnumerator enumerator = cache.GetEnumerator();
            while (enumerator.MoveNext())
            {
                cache.Remove(enumerator.Key.ToString());
            }

            RespondentInfo.Success(this.ControllerContext, new OperInfo()
            {
                Message = "已清空所有服务器缓存",
                Link = Request.UrlReferrer.ToString()
            });

            return new EmptyResult();
        }
    }
}
